package com.gzceb.zhgjj.web.dao;
// default package

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.gzceb.zhgjj.web.entity.LoanAuth;

/**
 	* A data access object (DAO) providing persistence and search support for LoanAuth entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see .LoanAuth
  * @author MyEclipse Persistence Tools 
 */

public class LoanAuthDAO extends HibernateDaoSupport  {
	     private static final Logger log = LoggerFactory.getLogger(LoanAuthDAO.class);
		//property constants
	public static final String CUSTNAME = "custname";
	public static final String PAPERKIND = "paperkind";
	public static final String PAPERID = "paperid";
	public static final String AMT = "amt";
	public static final String TERM = "term";
	public static final String RATE = "rate";
	public static final String RETUTYPE = "retutype";
	public static final String INDIISSUEDATE = "indiissuedate";
	public static final String INPTIME = "inptime";
	public static final String ISREVOKED = "isrevoked";
	public static final String REVOKEDDATE = "revokeddate";
	public static final String REVOKEDTYPE = "revokedtype";
	public static final String RVKINPDATE = "rvkinpdate";



	protected void initDao() {
		//do nothing
	}
    
    public void save(LoanAuth transientInstance) {
        log.debug("saving LoanAuth instance");
        try {
            getHibernateTemplate().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(LoanAuth persistentInstance) {
        log.debug("deleting LoanAuth instance");
        try {
            getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public LoanAuth findById( java.lang.String id) {
        log.debug("getting LoanAuth instance with id: " + id);
        try {
            LoanAuth instance = (LoanAuth) getHibernateTemplate()
                    .get("com.gzceb.zhgjj.web.entity.LoanAuth", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    public LoanAuth findByContCode(java.lang.String contCode){
    	log.debug("getting loanAuth instance with contCode: " + contCode);
    	try{
    		return findById(contCode);
    	} catch (RuntimeException re){
    		log.error("get failed", re);
    		throw re;
    	}
    }
    
    public List findByExample(LoanAuth instance) {
        log.debug("finding LoanAuth instance by example");
        try {
            List results = getHibernateTemplate().findByExample(instance);
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding LoanAuth instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from LoanAuth as model where model." 
         						+ propertyName + "= ?";
		 return getHibernateTemplate().find(queryString, value);
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByCustname(Object custname
	) {
		return findByProperty(CUSTNAME, custname
		);
	}
	
	public List findByPaperkind(Object paperkind
	) {
		return findByProperty(PAPERKIND, paperkind
		);
	}
	
	public List findByPaperid(Object paperid
	) {
		return findByProperty(PAPERID, paperid
		);
	}
	
	public List findByAmt(Object amt
	) {
		return findByProperty(AMT, amt
		);
	}
	
	public List findByTerm(Object term
	) {
		return findByProperty(TERM, term
		);
	}
	
	public List findByRate(Object rate
	) {
		return findByProperty(RATE, rate
		);
	}
	
	public List findByRetutype(Object retutype
	) {
		return findByProperty(RETUTYPE, retutype
		);
	}
	
	public List findByIndiissuedate(Object indiissuedate
	) {
		return findByProperty(INDIISSUEDATE, indiissuedate
		);
	}
	
	public List findByInptime(Object inptime
	) {
		return findByProperty(INPTIME, inptime
		);
	}
	
	public List findByIsrevoked(Object isrevoked
	) {
		return findByProperty(ISREVOKED, isrevoked
		);
	}
	
	public List findByRevokeddate(Object revokeddate
	) {
		return findByProperty(REVOKEDDATE, revokeddate
		);
	}
	
	public List findByRevokedtype(Object revokedtype
	) {
		return findByProperty(REVOKEDTYPE, revokedtype
		);
	}
	
	public List findByRvkinpdate(Object rvkinpdate
	) {
		return findByProperty(RVKINPDATE, rvkinpdate
		);
	}
	

	public List findAll() {
		log.debug("finding all LoanAuth instances");
		try {
			String queryString = "from LoanAuth";
		 	return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public LoanAuth merge(LoanAuth detachedInstance) {
        log.debug("merging LoanAuth instance");
        try {
            LoanAuth result = (LoanAuth) getHibernateTemplate()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(LoanAuth instance) {
        log.debug("attaching dirty LoanAuth instance");
        try {
            getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(LoanAuth instance) {
        log.debug("attaching clean LoanAuth instance");
        try {
            getHibernateTemplate().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

	public static LoanAuthDAO getFromApplicationContext(ApplicationContext ctx) {
    	return (LoanAuthDAO) ctx.getBean("LoanAuthDAO");
	}
}